//
//  StatusTopView.swift
//  我的微博
//
//  Created by Creator on 15/10/15.
//  Copyright © 2015年 Creator. All rights reserved.
//

import UIKit
import SDWebImage

class StatusTopView: UIView {

   
    var status: Status? {
        didSet {
            if let url = status?.user?.imageURL {
                iconView.sd_setImageWithURL(url)
            }
            nameLable.text = status?.user?.name ?? ""
            vipIconView.image = status?.user?.vipImage
            memberIconView.image = status?.user?.memberImage
            timeLable.text = "刚刚"
            sourceLable.text = "来自 微博.com"
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        backgroundColor = UIColor.clearColor()
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
     /// 搭建界面
    private func setupUI() {
        
        // 添加顶部分割视图
        let sepView = UIView()
        sepView.backgroundColor = UIColor(white: 0.8, alpha: 1.0)
        addSubview(sepView)
        sepView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        // 添加控件
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(timeLable)
        addSubview(sourceLable)
        addSubview(memberIconView)
        addSubview(vipIconView)
        
        // 自动布局
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: sepView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        nameLable.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 12, y: 0))
        timeLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 12, y: 0))
        sourceLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: timeLable, size: nil, offset: CGPoint(x: 12, y: 0))
        memberIconView.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: nameLable, size: nil, offset: CGPoint(x: 12, y: 0))
        vipIconView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 8))
        
    }
    
    
    // MARK: - 懒加载控件
    
    ///  头像
    private lazy var iconView: UIImageView =  UIImageView()
    ///  姓名
    private lazy var nameLable: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    ///  时间标签
    private lazy var timeLable: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    ///  来源标签
    private lazy var sourceLable: UILabel = UILabel(color: UIColor.lightGrayColor(), fontSize: 9)
    ///  会员图标
    private lazy var memberIconView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    ///  vip 图标
    private lazy var vipIconView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    
    
    
}
